/**
 * @param {string} s
 * @return {number}
*/
var balancedStringSplit = function(s) {
  let left = 0, right = 0, result = 0;
  for(let i = 0; i < s.length; i++) {
    if(s[i] == 'L') {
      left++;
    } else {
      right++;
    }
    if(left == right) {
      result++;
      left = 0;
      right = 0;
    }
  }
  return result;
};
let s = "RLRRLLRLRL";
console.log(balancedStringSplit(s));
s = "RLLLLRRRLR";
console.log(balancedStringSplit(s));
s = "LLLLRRRR";
console.log(balancedStringSplit(s));
s = "RLRRRLLRLL";
console.log(balancedStringSplit(s));
